home *** CD-ROM | disk | FTP | other *** search
- #!/usr2/local/bin/perl -w
-
- use SDBM_File;
- use Fcntl;
- use POSIX;
-
- require "cgilib.pl";
-
-
- sub calcTotals
- {
- my $votes = 0;
- my $sum = 0;
- my $i = 1;
-
- foreach (@_)
- {
- $sum += $_*$i++;
- $votes += $_;
- }
-
- return ($sum/$votes,$votes);
- }
-
- readParse(*dict);
-
- print <<EOH;
- Content-type: text/html
-
- <HTML>
- <HEAD><TITLE>Waite Movie Reviews</TITLE></HEAD>
- <BODY>
-
- <H1>Welcome to Waite Movie Reviews</H1>
- <HR>
- EOH
-
- # Display the dbm record for each movie, sorted by movie title
- #
- # Data is stored in the following format:
- # Field Desc
- # 0 last score given
- # 1 # of scores of 1
- # 2 # of scores of 2
- # . . .
- # 10 # of scores of 10
- # 11 domain of last voter 30 bytes
- #
-
- # If a vote is being registered
-
- if ($dict{'movie'} &&
- $dict{'movie'} !~ /</ &&
- $dict{'score'} >= 1 &&
- $dict{'score'} <= 10)
- {
- tie %movies, SDBM_File, 'movies', O_CREAT|O_RDWR, 0660;
-
- print "Your vote of $dict{score} out of 10 for ",
- "<B>$dict{movie}</B> has been recorded.<HR>\n";
-
- $movie = $dict{'movie'};
- @rec = unpack("l11a30",$movies{$movie});
- $rec[11] = $ENV{'REMOTE_HOST'};
- $rec[0] = $dict{'score'};
- $rec[$dict{'score'}]++;
- $movies{$movie} = pack("l11a30",@rec);
-
- untie %movies;
- }
-
- tie %movies, SDBM_File, 'movies', O_CREAT|O_RDONLY, 0660;
-
- foreach $title (sort keys(%movies))
- {
- # unpack the record into an array
- @rec = unpack("l11a30",$movies{$title});
-
- # calculate the average and total number of votes
- ($avg, $votes) = calcTotals(@rec[1..10]);
-
- print "<H2>$title</H2><BLOCKQUOTE>";
- print '<B>Average: ';
- printf('%2.2f',$avg);
- print " Votes: $votes</B><BR>\n";
- print '<IMG SRC="ht72a.pl?score=', join('+',@rec[1..10]),
- qq{" ALT="};
- foreach (1..10)
- {
- print "$_:$rec[$_] ";
- }
- print qq{"><BR>\n};
- print "Last vote from <B>$rec[11]</B> ";
- print "who gave $title a $rec[0] out of 10.\n";
-
- # Build the Form for voting for this movie
- print qq{<FORM ACTION="$ENV{'SCRIPT_NAME'}">};
- print qq{<INPUT TYPE="hidden" NAME="movie" value="$title">};
- print qq{<SELECT NAME="score">};
- # output <OPTION> 1 <OPTION> 2 ... <OPTION> 10
- print join '<OPTION>', ' ', 1..10;
- print '</SELECT><INPUT TYPE="submit" value="Vote"></FORM>';
- print "</BLOCKQUOTE><BR>\n";
- }
-
- # Build the Form for voting for 'Other'
- print "<H2>Other</H2><BLOCKQUOTE>";
- print qq{<FORM ACTION="$ENV{'SCRIPT_NAME'}">};
- print qq{<INPUT NAME="movie">};
- print qq{<SELECT NAME="score">};
- print join '<OPTION>', ' ', 1..10;
- print '</SELECT><INPUT TYPE="submit" value="Vote"></FORM>';
- print "</BLOCKQUOTE>";
-
- print '<HR></BODY></HTML>';
- 1;
-
-